<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <base th:href="@{/}">
    <meta charset="UTF-8">
    <title>公告列表</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css" />
    <link href="/css/style1.css" rel="stylesheet">
    <link href="/css/style.css" rel="stylesheet">
    <script src="/js/jquery.min.js"></script>
    <script type="text/javascript" th:inline="javascript">
        // 处理删除公告的函数
        function deleteBoard(bid){
            $.ajax(
                {
                    url : [[@{/admin/deleteBoard}]],
            type : "post",
                data : {
                id : bid
            },
            success : function(obj){
                if(obj == "no"){
                    alert("该公告存在关联不允许删除！");
                }else{
                    alert(obj);
                    // 成功删除后刷新网页
                    location.reload();
                }
            },
            error : function() {
                alert("处理删除公告异常！");
            }
        }
        );
        }
    </script>
</head>

<body>
<div th:insert="~{admin/header1}"></div>
<main id="main">
    <section class="breadcrumbs">
        <div class="container">
            <div class="d-flex justify-content-between align-items-center">
                <ol>
                    <li><a href="#">首页</a></li>
                    <li><a href="#">公告列表</a></li>
                </ol>
            </div>
        </div>
    </section>
    <section class="inner-page">
        <div class="container">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">公告列表</h3>
                </div>
                <div class="card-body">
                    <form th:action="@{/admin/boardList}" class="navbar-form navbar-right" style="display: flex;">
                        <div class="form-group" >
                            <input type="text" class="form-control" name="keyword" placeholder="请输入搜索关键词" th:value="${keyword}" style="height: 40px; margin-top:-1px ;" />
                        </div>
                        <button type="submit" class="btn" style="margin-top: -1px;  margin-left: 10px; background-color: #0accce;color: white">搜索</button>
                    </form>
                    <div class="table-responsive">
                        <table class="table text-center">
                            <thead>
                            <tr>
                                <th>编号</th>
                                <th>标题</th>
                                <th>内容</th>
                                <th>发布人</th>
                                <th>发布日期</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody class="text-center">
                            <tr th:each="board : ${announcements}">
                                <td th:text="${board.id}"></td>
                                <td th:text="${#strings.abbreviate(board.title, 10)}"></td>
                                <td th:text="${#strings.abbreviate(board.content,20)}"></td>
                                <td th:text="${board.fbr}"></td>
                                <td th:text="${board.fbrq}"></td>
                                <td>
                                     <a class="btn btn2 btn-sm" th:href="@{/admin/toUpdateBoard/{id}(id=${board.id})}">修改</a>
                                                                       <a class="btn btn1 btn-sm" th:href="'javascript:deleteBoard(' + ${board.id} +')'">删除</a>

                                </td>
                            </tr>
                            <tr>
                                <td colspan="6" style="border: none;">
                                    <ul class="pagination justify-content-center">
                                        <li class="page-item" th:if="${currentPage} != 1">
                                            <a class="page-link"
                                               th:href="@{/admin/boardList(currentPage=${currentPage - 1})}">上一页</a>
                                        </li>
                                        <li class="page-item disabled">
                                            <a class="page-link" href="#">第<span
                                                    th:text="${currentPage}"></span>页</a>
                                        </li>
                                        <li class="page-item disabled">
                                            <a class="page-link" href="#">共<span
                                                    th:text="${totalPage}"></span>页</a>
                                        </li>
                                        <li class="page-item" th:if="${currentPage} !=${totalPage}">
                                            <a class="page-link"
                                               th:href="@{/admin/boardList(currentPage=${currentPage + 1})}">下一页</a>
                                        </li>
                                    </ul>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </section>
</main>
<script src="js/main.js"></script>
</body>

</html>


